<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">商品管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">规格基本信息</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                	<div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品ID：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="productId" class="form-control" readOnly>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">规格名称：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="summaryName" class="form-control" placeholder="请输入规格名称"
                                                   required onkeyup = "ValidateValue(this)">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">规格描述：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="summaryDesc" class="form-control"
                                                   placeholder="请输入规格描述" onkeyup = "ValidateValue(this)">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-primary" onclick="category_modify()"
                        style="margin-left:15px;margin-bottom:30px;">发布
                </button>
                <button class="btn btn-default" id="cancel" style="margin-left:15px;margin-bottom:30px;">
                    取消
                </button>
            </form>
        </div>
    </div>
</div>
<script>
	function ValidateValue(textbox) {
		var IllegalString = "[`~!#$^&*()=|{}':;',\\[\\].<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？-+@&%_]‘’";
		var textboxvalue = textbox.value;
		var index = textboxvalue.length - 1;
		var s = textbox.value.charAt(index);
		if (IllegalString.indexOf(s) >= 0) {
			s = textboxvalue.substring(0, index);
			textbox.value = s;
		}
	}

	var images = [],descs=[];
	var currentI = 0;
	
	$(function(){
		var productId = "${productId}";
		var productSummaryId = "${productSummaryId}";
		var baseURL = "${webPath}/productSummary/detail";
	  	var json_package = {
	       "head": {},
	       "body": {
	       	"productSummaryId": productSummaryId
	       }
	   	}
		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	      if (typeof result == 'string') result = JSON.parse(result);
	      if (result.body.result == '1') {
	          alert(result.body.description)
	      } else {
	      	var productSummary = result.body.productSummary;
	      	$("#productId").val(productSummary.productId);
	      	$("#summaryName").val(productSummary.summaryName);
	      	$("#summaryDesc").val(productSummary.summaryDesc);
	      }
	  	})
	});
	
	function category_modify() {
		
    	var baseURL = "${webPath}/productSummary/modify";
    	var productId = "${productId}";
		var productSummaryId = "${productSummaryId}";
        var summaryName = $('#summaryName').val();
        var summaryDesc = $('#summaryDesc').val();
        
        var json_package = {
       		"head": {},
            "body": {
                "productSummaryId": productSummaryId,
            	"productId": productId,
                "summaryName": summaryName,
                "summaryDesc": summaryDesc
            }
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                alert('修改成功！')
                window.location.reload(true);
            } else {
                alert('修改失败！')
            }
        })
    }
	$(function () {
        $('#cancel').click(function () {
        	var productId = "${productId}";
            window.location.href = "${webPath}toProductSummary/"+productId;
        })
    });
   
</script>
</body>
</html>